﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace Marmat.Forms.Skin
{
    /// <summary>
    /// 面包屑的绘制路径服务提供类。
    /// </summary>
    public static class RectangleBreadcrumbExtension
    {
        /// <summary>
        /// 根据给定的矩形生产面包屑的开始节点的绘制路径。
        /// </summary>
        /// <param name="rect">矩形对象</param>
        /// <returns></returns>
        public static GraphicsPath GetBreadcrumbStartNodePath(this Rectangle rect)
        {
            return GetBreadcrumbStartNodePath(rect, Math.Min(rect.Height, rect.Width) / 2);
        }

        /// <summary>
        /// 根据给定的矩形生产面包屑的开始节点的绘制路径。
        /// </summary>
        /// <param name="rect">矩形对象</param>
        /// <param name="indent">缩进距离，采用像素点作为缩进单位。</param>
        /// <returns></returns>
        public static GraphicsPath GetBreadcrumbStartNodePath(this Rectangle rect, int indent)
        {
            GraphicsPath path = new GraphicsPath();
            if (rect.Width == 0 || rect.Height == 0)
                throw new ArgumentException();
            Point start = rect.Location;
            Point end = new Point(rect.Right, rect.Y);
            path.AddLine(start, end);
            start = end;
            end = new Point(end.X + indent, end.Y + Math.Min(rect.Height, rect.Width) / 2);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.Right, rect.Bottom);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X, rect.Bottom);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X, rect.Y);
            path.AddLine(start, end);
            path.CloseFigure();
            return path;
        }

        /// <summary>
        /// 根据给定的矩形生产面包屑的中间节点的绘制路径。
        /// </summary>
        /// <param name="rect">矩形对象</param>
        /// <returns></returns>
        public static GraphicsPath GetBreadcrumbMiddleNodePath(this Rectangle rect)
        {
            return GetBreadcrumbMiddleNodePath(rect, Math.Min(rect.Height, rect.Width) / 2);
        }

        /// <summary>
        /// 根据给定的矩形生产面包屑的中间节点的绘制路径。
        /// </summary>
        /// <param name="rect">矩形对象</param>
        /// <param name="indent">缩进距离，采用像素点作为缩进单位。</param>
        /// <returns></returns>
        public static GraphicsPath GetBreadcrumbMiddleNodePath(this Rectangle rect, int indent)
        {
            GraphicsPath path = new GraphicsPath();
            if (rect.Width == 0 || rect.Height == 0)
                throw new ArgumentException();
            Point start = rect.Location;
            Point end = new Point(rect.Right, rect.Y);
            path.AddLine(start, end);
            start = end;
            end = new Point(end.X + indent, end.Y + Math.Min(rect.Height, rect.Width) / 2);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.Right, rect.Bottom);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X, rect.Bottom);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X + indent, rect.Y + Math.Min(rect.Height, rect.Width) / 2);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X, rect.Y);
            path.AddLine(start, end);
            path.CloseFigure();
            return path;
        }

        /// <summary>
        /// 根据给定的矩形生产面包屑的结束节点的绘制路径。
        /// </summary>
        /// <param name="rect">矩形对象</param>
        /// <returns></returns>
        public static GraphicsPath GetBreadcrumbEndNodePath(this Rectangle rect)
        {
            return GetBreadcrumbEndNodePath(rect, Math.Min(rect.Height, rect.Width) / 2);
        }
        /// <summary>
        /// 根据给定的矩形生产面包屑的结束节点的绘制路径。
        /// </summary>
        /// <param name="rect">矩形对象</param>
        /// <returns></returns>
        /// <param name="indent">缩进距离，采用像素点作为缩进单位。</param>
        public static GraphicsPath GetBreadcrumbEndNodePath(this Rectangle rect, int indent)
        {
            GraphicsPath path = new GraphicsPath();
            if (rect.Width == 0 || rect.Height == 0)
                throw new ArgumentException();
            Point start = rect.Location;
            Point end = new Point(rect.Right, rect.Y);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.Right, rect.Bottom);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X, rect.Bottom);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X + indent, rect.Y + Math.Min(rect.Height, rect.Width) / 2);
            path.AddLine(start, end);
            start = end;
            end = new Point(rect.X, rect.Y);
            path.AddLine(start, end);
            path.CloseFigure();
            return path;
        }
    }
}
